package com.ehotting.edsta.mqbd.driverAdapt.http.caller;


import com.ehotting.edsta.mqbd.api.enums.SysModuleEnum;
import com.ehotting.edsta.mqbd.driverAdapt.service.IDriverAdaptService;
import com.ehotting.mqbd.api.MqActionConstants;
import com.ehotting.mqbd.api.bean.CommonRequest;
import com.ehotting.mqbd.api.bean.CommonResponse;
import com.ehotting.mqbd.api.bean.MQDataAble;
import com.ehotting.mqbd.api.bean.MQHttpData;
import com.ehotting.mqbd.api.bean.solver.SolverStateBean;
import com.ehotting.mqbd.api.enums.SendTypeEnum;
import com.ehotting.mqbd.core.call.CallerAbstract;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.ArrayUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;


@Slf4j
public class DriverAdaptCaller extends CallerAbstract {

    private static Logger logger = LoggerFactory.getLogger(DriverAdaptCaller.class);

    @Autowired
    private IDriverAdaptService driverAdaptService;

    @Override
    public void doAction(SolverStateBean serverState, MQDataAble mqData) throws Exception {
        logger.info("Start doAction.");
        MQHttpData data  = (MQHttpData) mqData;
        data.setSendType(new SendTypeEnum[]{SendTypeEnum.REDIS_RESPONSE_BODY});
        CommonResponse commonResponse = null;
        if(MqActionConstants.RE_POST.equals(data.getAction())){
             commonResponse = driverAdaptService.rePostService(data.getRequest(),serverState.getSolverInfo(),mqData.getAuthorization());
        }else if(MqActionConstants.RE_UPLOAD.equals(data.getAction())){
             commonResponse = driverAdaptService.rePostUploadService(data.getRequest(),serverState.getSolverInfo(),mqData.getAuthorization());
        }else if(MqActionConstants.RE_POST_BY_BROWSER.equals(data.getAction())){
             commonResponse = driverAdaptService.rePostService(data.getRequest(),serverState.getSolverInfo(),mqData.getAuthorization());
        }else if(MqActionConstants.RE_UPLOAD_BY_BROWSER.equals(data.getAction())){
             commonResponse = driverAdaptService.rePostUploadService(data.getRequest(),serverState.getSolverInfo(),mqData.getAuthorization());
        }
        data.setResponse(commonResponse);

//        data.setLogRequest(false);
//        data.setLogResponse(false);
//        data.setSendRequest(false);

        logger.info("Finish doAction.");
    }

    @Override
    public void validData(MQDataAble mqDataAble) {

    }

    @Override
    public String getModuleName() {
        return SysModuleEnum.DRIVER_ADAPT.getName();
    }


}
